<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
    <div class="container">
        <a class="navbar-brand" href="#">我的博客</a>
        <div>
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a class="nav-link" href="{% url 'article:article_list' %}">文章</a>
                </li>
                {% if user.is_authenticated %}
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'article:article_create' user.id %}">写文章</a>
                    </li>
                    <!-- 如果用户已经登录，则显示用户名下拉框 -->
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button"
                           data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                            {{ user.username }}
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                            <a class="dropdown-item" href='{% url "userprofile:edit" user.id %}'>个人信息</a>
                            <a class="dropdown-item" href="{% url "userprofile:delete" user.id %}">删除用户</a>
                            <a class="dropdown-item" href='{% url "userprofile:logout" %}'>退出登录</a>
                        </div>
                    </li>
                    <!-- 如果用户未登录，则显示 “登录” -->
                {% else %}
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'userprofile:login' %}">登录</a>
                    </li>
                    <!-- if 语句在这里结束 -->
                {% endif %}
            </ul>
        </div>
    </div>
</nav>